﻿using CustomPlayerEffects;
using PluginAPI.Core;
using PluginAPI.Core.Attributes;
using PluginAPI.Enums;
using PluginAPI.Events;
using System.ComponentModel;
using UnityEngine;
using Utils;

namespace RounEvent.Event
{
    public class HappyEvent
    {
        string[] commands = new string[] { "event", "eve" };

        [PluginEvent(ServerEventType.RemoteAdminCommandExecuted)]
        public void OnRemoteCommandRun(RemoteAdminCommandExecutedEvent ev)
        {
            string command = ev.Command.ToLower();

            if (!commands.Contains(command)) return;

            if (ev.Arguments[0] != "happy") return;

            if (ev.Arguments.Length == 1)
            {
                this.DoNoticeHappy();
                return;
            }


            if (ev.Arguments.Length == 2 && ev.Arguments[1] == "done")
            {
                this.DoNoticeHappyDone();
                return;
            }
        }



        [Description("")] Coroutine m_HappyCOR;

        private void DoNoticeHappy()
        {
            Cassie.Message("WOLF WOLF WOLF");
            Cassie.Message("天黑请闭眼，<color=red>狼人</color> 请睁眼", false, false, true);

            m_HappyCOR = TimeCoroutine.Loop(
                120,
                1,
                () => Player.GetPlayers().FindAll(e => e.IsAlive).ForEach(e => e.ReferenceHub.playerEffectsController.ChangeState<FogControl>(5, 3, false)),
                () => DoNoticeHappyDone());
        }
        private void DoNoticeHappyDone()
        {
            TimeCoroutine.Stop(m_HappyCOR);
            Cassie.Message("WOW WOW WOW");
            Cassie.Message("天亮请睁眼!", false, false, true);
        }

    }
}
